'use strict';
import Base from './base.js';

export default class extends Base {

	// 会员三期
	async sanqiAction(){

		let orid = this.userinfo.departmentid;

		if (this.isPost) {

			let data = this.post();

			let cunzai = await this.model('or_vipsanqi').where({departmentid: orid}).find();

			if (!think.isEmpty(cunzai)) {
				let geng = await this.model('or_vipsanqi').where({departmentid: orid}).update({fuwuqi: data.fuwuqi, pudianqi: data.pudianqi});
				return geng?this.success('更改成功'):this.fail('更改失败');
			}

			data.departmentid = orid;

			let tianjia = await this.model('or_vipsanqi').add(data);

			return tianjia?this.success('更改成功'):this.fail('更改失败');

		} else {
			let san = await this.model('or_vipsanqi').where({departmentid: orid}).find();
			if (think.isEmpty(san)) {
				return this.json({fuwuqi: 0, pudianqi: 0})
			}
			return this.json(san);
		}

		
	}









}